<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2023 yoncron All rights reserved.
// +----------------------------------------------------------------------
// | Author: yoncron <yoncron@163.com>
// +----------------------------------------------------------------------
namespace app\queue\redis\common;

use app\service\ExceptionService;
use support\Container;
use Webman\RedisQueue\Consumer;

class CommonQueue implements Consumer
{
    public $queue = 'common_queue';
    public $connection = 'default';

    public function consume($data){
        $class_name = $data['class'];
        $method_name = $data['method'];
        try {
            if(class_exists($class_name)){
                $class = Container::get($class_name);
                if(method_exists($class,$method_name)){
                    if(isset($data['args'])){
                        call_user_func([$class,$method_name],$data['args']);
                    }
                    else{
                        call_user_func([$class,$method_name]);
                    }
                }
                else{
                    throw new \Exception("method no exist");
                }
            }
            else{
                throw new \Exception("class no exist");
            }
        } catch (\Exception $e) {
            ExceptionService::addLog($e);
        }

    }
}